{template 'common/header'}
{if in_array($m, $sysmods)}
	<ul class="we7-page-tab">
		{loop $active_sub_permission $active_menu}
			{if permission_check_account_user($active_menu['permission_name'], false) && (empty($active_menu['is_display']) || is_array($active_menu['is_display']) && in_array($_W['account']['type'], $active_menu['is_display']))}
				<li {if $m == $active_menu['active']}class="active"{/if}><a href="{$active_menu['url']}">{$active_menu['title']}</a></li>
			{/if}
		{/loop}
	</ul>
{else}
	<ul class="we7-page-tab">
		{if !empty($_W['current_module']['isrulefields']) &&!empty($_W['account']) && in_array($_W['account']['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))}<li class="active"><a href="{url 'platform/reply' array('module_name' => $m, 'version_id' => intval($_GPC['version_id']))}">关键字链接入口 </a></li>{/if}
		{if !empty($frames['section']['platform_module_common']['menu']['platform_module_cover'])}
		<li><a href="{url 'platform/cover' array('module_name' => $m, 'version_id' => intval($_GPC['version_id']))}">封面链接入口</a></li>
		{/if}
	</ul>	
{/if}
{if $m == 'keyword' || $m == 'userapi' || !in_array($m, $sysmods)}
	<div id="js-keyword-display" ng-controller="KeywordDisplay" ng-cloak>
		<div class="search-box we7-margin-bottom">
			{if in_array($m, $sysmods) && $m != 'userapi'}
			<select class="we7-margin-right" ng-model="keywordType" ng-change="changeType()">
				<option value="">全部</option>
				<option value="news" >回复图文</option>
				<option value="apply">回复模块</option>
				<option value="voice">回复语音</option>
				<option value="basic">回复文字</option>
				<option value="music">回复音乐</option>
				<option value="images" >回复图片</option>
				<option value="video" >回复视频</option>
			</select>
			{/if}

			<form action="./index.php" method="get" class="form-horizontal search-form" role="form">
			<div class="search-form">
				<div class="input-group  search-form">
					<input type="hidden" name="c" value="platform">
					<input type="hidden" name="a" value="reply">
					<input type="hidden" name="module_name" value="{$_GPC['module_name']}" />
					<input type="hidden" name="status" value="{$status}" />

					<input name="type" type="hidden" value="{$_GPC['type']}">
					<span class="input-group-btn">
						<select class="we7-select" name="search_type">
							<option value="keyword" {if $_GPC['search_type'] == 'keyword'}selected{/if}>关键字</option>
							<option value="rule" {if $_GPC['search_type'] == 'rule'}selected{/if}>规则名</option>
						</select>
					</span>
					<input class="form-control" name="keyword" type="text" value="{$_GPC['keyword']}" autocomplete="false" placeholder="输入规则名称或关键字名称" style="width: 330px;">
					<span class="input-group-btn"><button class="btn btn-default"><i class="fa fa-search"></i></button></span>
				</div>
			</div>
			</form>
			<a href="{url 'platform/reply/post' array('module_name' => $m)}" class="btn btn-primary">添加{if $m == 'userapi'}自定义接口{else}关键字{/if}回复</a>
			{if in_array($m, $sysmods) && $m != 'userapi'}<a href="{url 'platform/reply/post' array('module_name' => 'apply')}" class="btn btn-default  we7-margin-left">添加应用关键字</a>{/if}
		</div>
		
		<div class="clearfix"></div>
		<div class=" {if !in_array($m, $sysmods)} we7-padding-bottom {/if}">
			<form action="{php echo url('platform/reply/delete');}" method="post" role="form" class="form we7-form" id="form1">
				<input type="hidden" name="m" value="{$m}">
				{if !empty($replies)}
					<table class="table we7-table table-hover">
						<col width="200px"/>
						<col>
						<col width=""/>
						<col width="120px"/>
						<col width="230px"/>
						<tr>
							<th>规则名称</th>
							<th>关键字</th>
							<th>回复内容</th>
							<th>开关</th>
							
							<th class="text-right">操作</th>
						</tr>
						<tr>
							{loop $replies $row}
							<td >
								<input id='rid-{$row['id']}' type="checkbox" name='rid[]' we7-check-all="we7-check-all" value="{$row['id']}"/>
								<label class="text-over reply-item-name" for="rid-{$row['id']}">&nbsp;<label class="text-over reply-item-name">{if !empty($row['name'])}{$row['name']}{/if}</label></label>
							</td>
							<td>
								{loop $row['keywords'] $kw}
								<span class="keyword-tag" data-toggle="tooltip" data-placement="bottom" title="{if $kw['type']==1}此关键字为精准触发{elseif $kw['type']==2}此关键字为包含触发{elseif $kw['type']==3}此关键字为正则匹配触发{/if}">{$kw['content']}</span>
								{if $kw['type'] == 4}<span class="form-control-static keyword-tag" data-toggle="tooltip" data-placement="bottom" title="托管">优先级在{$row['displayorder']}之下直接生效</span>{/if}
								{/loop}
							</td>
							<td>
								<span class="">
								{if $m == 'userapi'}
									自定义
								{elseif in_array($row['module'], $sysmods)}
									共{$row['allreply']['sum']}条（{if $row['allreply']['basic'] > 0}{$row['allreply']['basic']}条文字 {/if}{if $row['allreply']['images'] > 0}{$row['allreply']['images']}条图片 {/if}{if $row['allreply']['news'] > 0}{$row['allreply']['news']}条图文 {/if}{if $row['allreply']['music'] > 0}{$row['allreply']['music']}条音乐 {/if}{if $row['allreply']['voice'] > 0}{$row['allreply']['voice']}条语音 {/if}{if $row['allreply']['video'] > 0}{$row['allreply']['video']}条视频 {/if}{if $row['allreply']['wxcard'] > 0}{$row['allreply']['wxcard']}条卡券{/if}）
								{else}
									{php echo cutstr($row['module_info']['title'], 10);}应用
								{/if}
								</span>
							</td>
							<td>
								<label>
									<div class="switch {if $row['status']} switchOn{/if}" id="key-{$row['id']}" ng-click="changeStatus({$row[id]})"></div>
								</label>
							</td>
							<td>
								<div class="link-group">
									{if in_array($row['module'], $sysmods)}
									<a href="{php echo url('platform/reply/post', array('module_name' => $m, 'rid' => $row['id']))}">编辑</a>
									{else}
									<a href="{php echo url('platform/reply/post', array('module_name' => $row['module'], 'rid' => $row['id']))}">编辑</a>
									{/if}
									<a href="javascript:void(0);" class="del" onclick="deleteReply('{php echo url("platform/reply/delete", array("m" => $row['module'], "rid" => $row["id"]))}')">删除</a>
									{loop $entries['rule'] $ext_menu}
									<a href="{$ext_menu['url']}&id={$row['id']}&rid={$row['id']}">{$ext_menu['title']}</a>
									{/loop}
								</div>
							</td>
						</tr>
						{/loop}
					</table>
					<div class="checkboxall">
						<input type="checkbox" name="rid[]" we7-check-all="we7-check-all" id="select_all"  class="we7-margin-left" value="1" />
						<label for="select_all">&nbsp;</label>
						<input type="submit" class="btn btn-danger" value="删除" onclick="if(!confirm('确定删除选中的规则吗？')) return false;"/>
						<input type="hidden" name="token" value="{$_W['token']}"/>
						<div class="text-right">
							{$pager}
						</div>
					</div>
				{else}
					<p class="text-center we7-margin-top">暂无数据</p>
				{/if}
			</form>
		</div>
	</div>
	<script>

		function deleteReply(url) {
			util.confirm(function () {
				window.location.href = url;
			}, function () {
				return false;
			}, '确认删除吗?');
		}

		$(function () {
			$('[data-toggle="tooltip"]').tooltip();
			$('#select_all').click(function(){
				$('#form1 :checkbox').prop('checked', $(this).prop('checked'));
			});
			$('#form1 :checkbox').click(function(){
				if(!$(this).prop('checked')) {
					$('#select_all').prop('checked', false);
				} else {
					var flag = 0;
					$('#form1 :checkbox[name="rid[]"]').each(function(){
						if(!$(this).prop('checked') && !flag) {
							flag = 1;
						}
					});
					if(flag) {
						$('#select_all').prop('checked', false);
					} else {
						$('#select_all').prop('checked', true);
					}
				}
			});
			angular.module('replyFormApp').value('config', {
				'type': '{$_GPC[type]}',
				'replyUrl': '{url 'platform/reply' array('module_name' => 'keyword')}',
			});
			angular.bootstrap($('#js-keyword-display'), ['replyFormApp']);
		});
	</script>
{elseif $m == 'special'}
	<div class="NoKeyword-list" id="js-special-display" ng-controller="SpecialDisplay" ng-cloak>
		<div class="table we7-tables">
			<table class="table we7-table table-hover vertical-middle">
				<col width="160px"/>
				<col />
				<col width="120px"/>
				<col width="180px"/>
				<tr>
					<th class="text-left">类型</th>
					<th class="text-left">关键字/模块</th>
					<th>状态</th>
					<th class="text-left">操作</th>
				</tr>
				{loop $mtypes $name $title}
				<tr>
					<td class="text-left">
						{$title}
					</td>
					<td class="text-left">
						{if !empty($setting[$name]['type'])}
							{if $setting[$name]['type'] == 'keyword'}
								{$setting[$name]['keyword']}
							{else}
								{$module[$setting[$name]['module']]['title']}
							{/if}
						{else}
							{if !empty($setting[$name]['keyword'])}
								{$setting[$name]['keyword']}
							{else}
								{$module[$setting[$name]['module']]['title']}
							{/if}
						{/if}
					</td>
					<td>
						<label>
							<div ng-class="switch_class['{$name}']" ng-click="changestatus('{$name}')"></div>
						</label>
					</td>
					<td>
						<div class="link-group text-left">
							<a href="{php echo url('platform/reply/post', array('module_name' => 'special', 'type' => $name))}" class="keyword-link">编辑</a>
						</div>
					</td>
				</tr>
				{/loop}
			</table>
		</div>
	</div>
	<script>
		$(function() {
			angular.module('replyFormApp').value('config', {
				{loop $mtypes $name $title}
					'{$name}' : '{$setting[$name]['type']}',
				{/loop}
				'url' : '{php echo url('platform/reply/change_status')}'
			});
			angular.bootstrap($('#js-special-display'), ['replyFormApp']);
		});
	</script>
{elseif $m == 'welcome'}
	<div class="alert we7-page-alert">
		<i class="wi wi-info-sign"></i>用户关注公众号时，发送的欢迎信息。
	</div>
	<div class="new-keyword" id="welcome" ng-cloak>
		<div class="we7-form" ng-controller="WelcomeDisplay">
			<form id="reply-form" class="form-horizontal form" action="{php echo url('platform/reply/post', array('module_name' => $m, 'rid' => $rule_keyword_id))}" method="post" enctype="multipart/form-data">
				<div>
					{php echo module_build_form('core', $rule_keyword_id, array('keyword' => false))}
				</div>
				<input type="submit" name="submit"  value="保存" class="btn btn-primary" style="padding: 6px 50px;"/>
				<input type="hidden" name="token" value="{$_W['token']}">
				<input type="hidden" name="m" value="{$m}">
				<input type="hidden" name="type" value="{$type}">
			</form>
		</div>
	</div>
	<script>
		require(['underscore'], function() {
			angular.bootstrap($('#welcome'), ['replyFormApp']);
		});
	</script>
{elseif $m == 'default'}
	<div class="alert we7-page-alert">
		<i class="wi wi-info-sign"></i>当系统不知道该如何回复粉丝的消息时，默认发送的内容。
	</div>
	<div class="new-keyword" id="default">
		<div id="a" class="we7-form" ng-controller="DefaultDisplay">
			<form id="reply-form" class="form-horizontal form" action="{php echo url('platform/reply/post', array('module_name' => $m, 'rid' => $rule_keyword_id))}" method="post" enctype="multipart/form-data">
				<div>
					{php echo module_build_form('core', $rule_keyword_id, array('keyword' => false))}
				</div>
				<input type="submit" name="submit"  value="保存" class="btn btn-primary" style="padding: 6px 50px;"/>
				<input type="hidden" name="token" value="{$_W['token']}">
				<input type="hidden" name="m" value="{$m}">
				<input type="hidden" name="type" value="{$type}">
			</form>
		</div>
	</div>
	<script>
		require(['underscore'], function() {
			angular.bootstrap($('#default'), ['replyFormApp']);
		});
	</script>
{elseif $m == 'service'}
	<div class="NoKeyword-list" id="js-service-display" ng-controller="serviceDisplay" ng-cloak>
		<div class="table we7-tables">
			<table class="table we7-table table-hover">
				<col width="160px"/>
				<col />
				<col width="120px"/>
				<tr>
					<th class="text-left">服务名称</th>
					<th class="text-left">功能说明</th>
					<th>状态</th>
				</tr>
				<tr ng-repeat="(id, api) in service track by id" ng-if="service">
					<td class="text-left">
						{{ api.name }}
					</td>
					<td class="text-left" ng-bind-html="api.description">
					</td>
					<td class="vertical-middle">
						<label>
							<div ng-class="api.switch == 'checked' ? 'switch switchOn' : 'switch'" ng-click="changeStatus(id)"></div>
						</label>
					</td>
				</tr>
				<tr ng-if="!service">
					<td colspan="3" class="text-center">
						暂无数据
					</td>
				</tr>
			</table>
		</div>
	</div>
	<script>
		$(function() {
			angular.module('replyFormApp').value('config', {
				'url' : "{php echo url('platform/reply/change_status')}",
				'service' : {php echo !empty($service_list) ? json_encode($service_list) : 'null'}
			});
			angular.bootstrap($('#js-service-display'), ['replyFormApp']);
		});
	</script>
{/if}
{template 'common/footer'}